DFRobot Power Shield: A Complete Guide
This video shows you how to use the DFRobot Power Shield for Arduino UNO. This code displays the output voltage at the serial monitor. See the video for complete instructions. This code displays the output voltage on the LCD1602 display. See the video for complete instructions. Please download the LCD1602 library in order to use this code.150-Basic code to control the output power of the DFRobot Power Shield
语言: C++
/*
* Arduino code to control DFRobot Power shield
* Using this code you can turn ON or turn OFF output power on DFRobot Power shield
*
* Written by Ahmad Shamshiri for Robojax.com on Sep 01, 2018 at 11:07 in Ajax, Ontario, Canada
* Watch a video instruction for this code:
*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
const float vFactor = 5.0; // (30000+7500)/7500 = 5
void setup() {
pinMode(13,OUTPUT);// pin to control power Chip On or OFF
digitalWrite(13, LOW);// initially turn it ON
Serial.begin(9600);
}
void loop() {
delay(4000);
digitalWrite(13, LOW);// turn the output power ON
Serial.println("Power ON");
delay(3000);// off for 3 seconds
digitalWrite(13, HIGH);//turn it OFF
Serial.println("Power OFF");
}
151-Code for a DFRobot Power Shield to use voltage sensing
语言: C++
/*
* Arduino code to control DF Robot Power shield
* Using this code you can turn ON or turn OFF the output power of the shield
* and also the voltage is sensed at A0 pin and displayed in the serial monitor
*
* Written by Ahmad Shamshiri for Robojax.com on Sep 01, 2018 at 11:07 in Ajax, Ontario, Canada
* Watch video instructions for this code: https://youtu.be/WUeLbif-6YQ
*
* This code has been downloaded from Robojax.com
* Get Arduino Code and watch videos at Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
const float vFactor = 5.0; // (30000+7500)/7500 = 5 // see watch video for full details
void setup() {
pinMode(13,OUTPUT);// pin to control power Chip On or OFF
digitalWrite(13, LOW);// initially turn it ON
Serial.begin(9600);
}
void loop() {
digitalWrite(13,LOW);// turn ON the power
int voltageRaw = analogRead(A0); // read A0 voltage
float voltage = voltageRaw *(5.0/1023.0) * vFactor; // convert RAW value to actual voltage
Serial.print("Voltage: ");
Serial.print(voltage, 3);
Serial.println("V");
delay(300);
if(voltage > 11.5)
{
digitalWrite(13,HIGH);// turn OFF the power
Serial.println("Voltage limit reached ");
delay(5000);
}else{
digitalWrite(13,LOW);// turn ON the power
}
delay(500);
Serial.println("=======");
}
152-Code for a DFRobot Power Shield to use an LCD1602 as a voltmeter
语言: C++
/*
* Arduino code to control DF Robot Power shield
* Using this code you can turn ON or turn OFF output power
* and display output voltage on LCD1602 as a voltmeter
*
* Written by Ahmad Shamshiri for Robojax.com on Sep 01, 2018 at 11:07 in Ajax, Ontario, Canada
* Watch video instruction for this code:https://youtu.be/WUeLbif-6YQ
*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
const float vFactor = 5.0; // (30000+7500)/7500 = 5
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(13,OUTPUT);// pin to control power Chip On or OFF
digitalWrite(13, LOW);// initially turn it ON
Serial.begin(9600);
// initialize the LCD,
lcd.begin();
// Turn on the backlight and print a message.
lcd.backlight();
lcd.clear();
lcd.setCursor (0,0); //
lcd.print("Robojax DF Robot");
lcd.setCursor (0,1); //
}
void loop() {
digitalWrite(13,LOW);// turn ON the power
int voltageRaw = analogRead(A0); // read A0 voltage
float voltage = voltageRaw *(5.0/1023.0) * vFactor; // convert RAW value to actual voltage
lcd.clear();// clear previous values from screen
lcd.setCursor (0,0); //character zero, line 1
lcd.print("Robojax V meter"); // print text
lcd.setCursor (0,1); //character zero, line 1
lcd.print("Voltage:"); // print text
lcd.setCursor (9,1); //character 9, line 1
lcd.print(voltage); // print voltage
lcd.setCursor (14,1); //character 14, line 1
lcd.print("V"); // print V
delay(500);
}
资源与参考
-
外部DFRobot 电源保护板(官方网站)dfrobot.com
-
内部DFRobot电源保护板原理图robojax.com
文件📁
没有可用的文件。