I'm recently making a product that can generate energy by stepping on the pedal that works similar to a bicycle. But I found some problems when I try to show the energy generation in AppInventor. May I have your help? Thank you so much!
First of all, I made an App to show the energy generation. The "Choice" is a picklist that I can choose which Bluetooth device I would like to connect to. So I can press on the "JDY-16" to select this. However, after pressing this, "ERROR 507, Is the device turned on?" is showed. I tried to restart the Arduino, import the program in to the board again, put my phone on the Bluetooth Module and change the coding but it the ERROR 507 is still showed. I'm not sure if there are problems on the AppInventor coding or the Arduino coding.
Secondly, let me explain the Arduino coding, it is part of my product. The servo motor used as an energy source. Therefore, energy generated by the motor will be used for the Arduino board and charging a rechargeable battery when I have spun it for a while. As I don't have a component to directly measure the current emitted by it, I tried to see how many LEDs can I light up if I spin the motor for a second and complete a circle. The result is 2 LEDs per second(only complete a circle). Therefore, I assume that the energy generated a second is 0.2J after some calculation. Finally, the energy generated will be sent to the JDY-16 Bluetooth module and be showed on the app.
Lastly, I would like to share the information I think I need to provide here: 1.Arduino Uno board 2.JDY-16 Bluetooth Module 3.9g Servo Motor 4.Breadboard 5.a 9V USB Rechargeable Lithium-ion Battery 6.an Xperia 5mkIV phone
Here is the coding of Arduino:(Please don't mind my notes)
\#include \<SoftwareSerial.h\> //allowing serial communication btw different pins
//defining port
\#define BT_RX_PIN 10
\#define BT_TX_PIN 11
\#define SERVO_PIN 9
SoftwareSerial bluetooth(BT_RX_PIN, BT_TX_PIN); //bluetooth is created here
unsigned long zero_millis = 0; //unsined long data type, 32bits, no negative no.
const unsigned long interval = 1000; //const constant, never changed
float energyGenerated = 0.0; //data type, 32bits, no. that has a decimal point
char one_or_zero = 0; //data type, store character as no. , 8bits
// Bluetooth commands
#define CMD_GET_ENERGY 'E'
void setup() {
pinMode(SERVO_PIN, OUTPUT);
bluetooth.begin(9600);
delay(100);
Serial.begin(9600); //begin() for setting baud rate(data trasmitted in a certain period)
pinMode(11, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis(); //mills(50), go back to 0 when it exceeds 50
if (currentMillis - zero_millis >= interval) { // Generate energy and store it in rechargeable batteries
zero_millis = currentMillis;
float energyPerSecond = 0.2; // Energy generated per second, adjust as needed
float timeInSeconds = (float)interval / 1000.0; // Convert interval to seconds
float energyGeneratedPerInterval = energyPerSecond * timeInSeconds;
energyGenerated += energyGeneratedPerInterval; //mean adding the value after this to the LHS, this makes energyGenerated become the total generation
}
if(Serial.available() \> 0) //many datum inside, see if any of them \>0
{
one_or_zero = Serial.read();
Serial.print(one_or_zero);
Serial.print("/n");
if(one_or_zero == '1')
digitalWrite(11, HIGH);
else if(one_or_zero == '0')
digitalWrite(11, LOW);
}
if (bluetooth.available()) {
char command = bluetooth.read();
if (command == CMD_GET_ENERGY) {
sendEnergyValue();
}
}
}
void sendEnergyValue() {
int energyValue = (int)energyGenerated; //int is a datatype
bluetooth.print(energyValue);
}
I expected to see the energy generation but ERROR 507 was showed.