HC-05 to control car has delays and disconnection - arduino

I made some simple code and car using 1 arduino, 1 hc-05, 2 L298N, and 4 batteries. I control them with the app Bluetooth RC controller on android. When I send a command on the app, the car sometimes has some delays, varying 4-8 seconds, sometimes it disconnects completely. Here is the code. I don't think the code has any problem and my friend brought up that the problem might be the distortion from a magnetic field because I use some lead to weld some wires
char t;
int fr1= 2;
int fr2=3;
int fl1=12;
int fl2=13;
int br1=4;
int br2=5;
int bl1 = 7;
int bl2=8;
int Mfr=6;//speed setting
int Mfl=9;
int Mbr=10;
int Mbl=11;
float Speed;
void setup() {
pinMode(fr1,OUTPUT); //fr1
pinMode(fr2,OUTPUT); //fr2
pinMode(fl1,OUTPUT); //fl1
pinMode(fl2,OUTPUT); //fl2
pinMode(br1,OUTPUT); //br1
pinMode(br2,OUTPUT); //br2
pinMode(bl1,OUTPUT); //bl1
pinMode(bl2,OUTPUT); //bl2
Serial.begin(9600);
}
void loop() {
if(Serial.available()){
t = Serial.read();
Serial.println(t);
}
if(t == 'F'){
digitalWrite(fr1, LOW);
digitalWrite(fr2, HIGH);
digitalWrite(fl1, LOW);
digitalWrite(fl2, HIGH);
digitalWrite(br1, LOW);
digitalWrite(br2, HIGH);
digitalWrite(bl1, LOW);
digitalWrite(bl2, HIGH);
}
else if(t == 'B'){
digitalWrite(fr1, HIGH);
digitalWrite(fr2, LOW);
digitalWrite(fl1, HIGH);
digitalWrite(fl2, LOW);
digitalWrite(br1, HIGH);
digitalWrite(br2, LOW);
digitalWrite(bl1, HIGH);
digitalWrite(bl2, LOW);
}
else if(t == 'L'){
digitalWrite(fr1, LOW);
digitalWrite(fr2, HIGH);
digitalWrite(fl1, HIGH);
digitalWrite(fl2, LOW);
digitalWrite(br1, HIGH);
digitalWrite(br2, LOW);
digitalWrite(bl1, LOW);
digitalWrite(bl2, HIGH);
}
else if(t == 'R'){
digitalWrite(fr1, HIGH);
digitalWrite(fr2, LOW);
digitalWrite(fl1, LOW);
digitalWrite(fl2, HIGH);
digitalWrite(br1, LOW);
digitalWrite(br2, HIGH);
digitalWrite(bl1, HIGH);
digitalWrite(bl2, LOW);
}
else if(t == 'S'){ //STOP (all motors stop)
digitalWrite(fr1, LOW);
digitalWrite(fr2, LOW);
digitalWrite(fl1, LOW);
digitalWrite(fl2, LOW);
digitalWrite(br1, LOW);
digitalWrite(br2, LOW);
digitalWrite(bl1, LOW);
digitalWrite(bl2, LOW);
}
}

Is it possible its gotten flooded by bytes, serial.read had to read? I imagine maybe the app is sending a lot of characters to the Arduino, is it possible to check/apply a (short) delay in that app?

Related

Arduino only executing one set of if-else

This code if for a simple robot car.
I'm trying to control the robot with 4 geared motors and L289 driver and standard RC Tx/Rx.
I have used some print statements to debug any errors.
When I try to move the robot forward/backward, I can see serial monitor printing froward/backward, but the robot doesn't move.
When I try to move if left/right it works fine. On commenting the left-right moving statements in code the robot does move forward and backward but fails to do so with all the if else statements uncommented.
Here's the code.
//Receiver pin
byte CH1_PIN = 9;
byte CH2_PIN = 10;
//Motor driver pins
int left_motor_pin1 = 4;
int left_motor_pin2 = 5;
int right_motor_pin1 = 6;
int right_motor_pin2 = 7;
void setup() {
// put your setup code here, to run once:
pinMode(CH1_PIN, INPUT);
pinMode(CH2_PIN, INPUT);
pinMode(left_motor_pin1, OUTPUT);
pinMode(left_motor_pin2, OUTPUT);
pinMode(right_motor_pin1, OUTPUT);
pinMode(right_motor_pin2, OUTPUT);
digitalWrite(left_motor_pin1, LOW);
digitalWrite(left_motor_pin2, LOW);
digitalWrite(right_motor_pin1, LOW);
digitalWrite(right_motor_pin2, LOW);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
int ch_1 = pulseIn(CH1_PIN, HIGH);
int ch_2 = pulseIn(CH2_PIN, HIGH);
drive(ch_1, ch_2);
delay(5);
}
void drive(int move_left_right, int move_fwd_back) {
// Set direction for moving forward
if ( move_fwd_back > 1700 ) {
digitalWrite(left_motor_pin1, HIGH);
digitalWrite(left_motor_pin2, LOW);
digitalWrite(right_motor_pin1, HIGH);
digitalWrite(right_motor_pin2, LOW);
Serial.println("forward");
}
// Set direction for moving backwards.
else if (move_fwd_back < 1300) {
digitalWrite(left_motor_pin1, LOW);
digitalWrite(left_motor_pin2, HIGH);
digitalWrite(right_motor_pin1, LOW);
digitalWrite(right_motor_pin2, HIGH);
Serial.println("reverse");
}
else {
digitalWrite(left_motor_pin1, LOW);
digitalWrite(left_motor_pin2, LOW);
digitalWrite(right_motor_pin1, LOW);
digitalWrite(right_motor_pin2, LOW);
Serial.println("NONE");
}
// Set direction for moving left
if ( move_left_right < 1300 ) {
digitalWrite(left_motor_pin1, HIGH);
digitalWrite(left_motor_pin2, LOW);
digitalWrite(right_motor_pin1, LOW);
digitalWrite(right_motor_pin2, HIGH);
Serial.println("left");
}
//set directionfor moving right
else if (move_left_right > 1700) {
digitalWrite(left_motor_pin1, LOW);
digitalWrite(left_motor_pin2, HIGH);
digitalWrite(right_motor_pin1, HIGH);
digitalWrite(right_motor_pin2, LOW);
Serial.println("right");
}
else {
digitalWrite(left_motor_pin1, LOW);
digitalWrite(left_motor_pin2, LOW);
digitalWrite(right_motor_pin1, LOW);
digitalWrite(right_motor_pin2, LOW);
Serial.println("NONE");
}
}
The issue is that you have two if-else conditions - both changing the same outputs. So the 2nd if-else condition will always override what the 1st one has done.
eg. if you want the motor to just move forward, the code would set the motors to both move forward - however, immediately afterwards, the code decides there is no left/right input so sets the motors to stop. This is so fast you don't see any movement in the motors.
To start with, I would change the code so that the decision regarding the left/right input is inside the else condition of the forward/backward condition. This would give the forward/backward input priority over the left/right input.
i.e.
if ( move_fwd_back > 1700 ) {
digitalWrite(left_motor_pin1, HIGH);
digitalWrite(left_motor_pin2, LOW);
digitalWrite(right_motor_pin1, HIGH);
digitalWrite(right_motor_pin2, LOW);
Serial.println("forward");
}
// Set direction for moving backwards.
else if (move_fwd_back < 1300) {
digitalWrite(left_motor_pin1, LOW);
digitalWrite(left_motor_pin2, HIGH);
digitalWrite(right_motor_pin1, LOW);
digitalWrite(right_motor_pin2, HIGH);
Serial.println("reverse");
}
else {
// Set direction for moving left
if ( move_left_right < 1300 ) {
digitalWrite(left_motor_pin1, HIGH);
digitalWrite(left_motor_pin2, LOW);
digitalWrite(right_motor_pin1, LOW);
digitalWrite(right_motor_pin2, HIGH);
Serial.println("left");
}
//set directionfor moving right
else if (move_left_right > 1700) {
digitalWrite(left_motor_pin1, LOW);
digitalWrite(left_motor_pin2, HIGH);
digitalWrite(right_motor_pin1, HIGH);
digitalWrite(right_motor_pin2, LOW);
Serial.println("right");
}
else {
digitalWrite(left_motor_pin1, LOW);
digitalWrite(left_motor_pin2, LOW);
digitalWrite(right_motor_pin1, LOW);
digitalWrite(right_motor_pin2, LOW);
Serial.println("NONE");
}
}

changing the value of a variable multiple times and keeping that variable value throughout the entire loop in arduino

In Arduino I am having issues where I can't change the value of a variable in the void loop(). Here is the code I use:
void setup() {
pinMode(10, INPUT);
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
int speed = 1000;
int sub = 100;
void loop() {
if (digitalRead(13) == HIGH) {
speed = speed-sub;
} else {
speed = speed;
}
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(speed);
if (digitalRead(13) == HIGH) {
speed = speed - sub;
} else {
speed = speed;
}
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(speed);
if (digitalRead(13) == HIGH) {
speed = speed - sub;
} else {
speed = speed;
}
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(speed);
}
Is there any way I can change the value of a variable multiple times during one loop and have that variable value kept until the end of the loop? Also, will I need to add a new function, and if so how should I go about it?
It seems that you want to control the speed of a running light using push button.
but in your code that is not possible because you use blocking function that will disable reading of button for a while.
i suggest you run the code in your mind line by line. then you will understood what i mean.

Why did my arduino program suddenly stop working?

So I have a project to make for school in which we had to make an arduino project from scratch. I'm relatively new to arduino and his coding and made a simple, yet fun project. I had the idea of making a sort of safe where you have to enter a key and after that, use a potentiometer to make the right combination to open the safe. I don't know what I did wrong but when I uploaded it to my arduino, the program got to the first lines and stopped after printing the first line to the serial monitor. There the program is stuck and doesn't do anything. The weird thing is that it worked 5 minutes ago but now it just wont. Can anyone help me please? My deadline is in a few hours and I can't fix it... Here is the code and a schematic:
Picture of the setup. The 2 resistors on the left are 1k, the other 2 are 10k.
//variabelen
const int pot = A0;
const int pinA = 6;
const int pinB = 5;
const int pinC = 2;
const int pinD = 3;
const int pinE = 4;
const int pinF = 7;
const int pinG = 8;
const int pinP = 9;
const int enter = 11;
const int reset = 12;
byte enterState = 0;
byte lastEnterState = 0;
byte resetState = 0;
byte lastResetState = 0;
int enterTimer = 0;
String wachtwoord;
String ingegeven = "";
//setup
void setup(){
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinP, OUTPUT);
pinMode(enter, INPUT);
pinMode(reset, INPUT);
Serial.begin(9600);
Serial.println("Geef een wachtwoord op voor de safe.");
wachtwoord = Serial.read();
}
//eigen methoden
void dispChar(int getal){
switch(getal){
case 0:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
break;
case 1:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
case 2:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
break;
case 3:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
break;
case 4:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 5:
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 6:
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 7:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
case 8:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 9:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
}
}
//Kijk of enter knop is ingedrukt
void onEnter(){
enterState = digitalRead(enter);
if(enterState == HIGH){
enterTimer++;
if(enterState != lastEnterState){
ingegeven += map(analogRead(pot), 0, 1023, 0, 9);
Serial.println(ingegeven);
enterTimer = 0;
}
}
delay(50); //Voorkomt bounce.
if(enterTimer > 50){
Serial.println("\nRESET");
enterTimer = 0;
ingegeven = "";
}
lastEnterState = enterState;
check();
}
bool check(){
if(ingegeven.equals(wachtwoord)){
return true;
} else{
if(ingegeven.length() > wachtwoord.length()){
Serial.println("FOUT!");
ingegeven = "";
return false;
}
}
}
//Kijk of reset knop is ingedrukt
void onReset(){
resetState = digitalRead(reset);
if(resetState != lastResetState){
if(resetState == HIGH){
ingegeven = "";
Serial.println("Geef een wachtwoord op voor de safe.");
wachtwoord = Serial.read();
}
}
delay(50); //Voorkomt bounce.
lastResetState = resetState;
}
//loop
void loop(){
while(!check()){
int getal = map(analogRead(pot), 0, 1023, 0, 9);
digitalWrite(pinP, HIGH);
dispChar(getal);
onEnter();
onReset();
}
Serial.println("CODE CORRECT!")
}
Thanks for the help!!

Can't get time right with arduino?

I have a small 7 segment led display and I wondered if I could get it to show me the last digit of the minute. Downloaded the Time library for Arduino and I tried several methods, with switch case and if else if, but all give the same result, the LED display shows only 0... Could you pinpoint what I did wrong?
#include <Time.h>
#include <TimeLib.h>
int led1=2;
int led2=3;
int led3=4;
int led4=5;
int led5=6;
int led6=7;
int led7=8;
int led8=9;
void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
pinMode(led6,OUTPUT);
pinMode(led7,OUTPUT);
pinMode(led8,OUTPUT);
}
void loop(){
time_t t=minute();
int digit1=t%10;
if(digit1==1){
digitalWrite(led5, HIGH);
digitalWrite(led3, HIGH);
}else if(digit1==2)
{
digitalWrite(led6, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
} else if(digit1==3)
{
digitalWrite(led4, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led2, HIGH);
}else if(digit1==4)
{
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led3, HIGH);
}else if(digit1==5)
{
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led2, HIGH);
}else if(digit1==6)
{
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
}else if(digit1==7)
{
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led3, HIGH);
}else if(digit1==8)
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
}else if(digit1==9)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
}else if(digit1==0)
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
}
}
You never write any of the pins to go low. When the next minute hits, the proper LEDS are probably turning on, but the old ones don't go off, so you don't see any change.
To avoid turning all the LEDS off and on again every cycle, I would store the last known digit and at each loop iteration, see if the digit has changed. If it has, turn off all of the lights and then run the code you posted here.
You haven't added low conditions hence when the pin is going high it is remaining high. Also, I have checked and I think that your wiring is not correct. I'm posting complete code below and connections accordingly.
#include <Time.h>
#include <TimeLib.h>
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;
int dp = 9;
void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
pinMode(led6,OUTPUT);
pinMode(led7,OUTPUT);
pinMode(led8,OUTPUT);
}
void loop(){
time_t t=minute();
int digit1=t%10;
if(digit1==0) {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
digitalWrite(dp, LOW);
}
else if(digit1==1) {
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp, LOW);
}
else if(digit1==2) {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp, LOW);
}
else if(digit1==3) {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp, LOW);
}
else if(digit1==4) {
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp, LOW);
}
else if(digit1==5) {
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp, LOW);
}
else if(digit1==6) {
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp, LOW);
}
else if(digit1==7) {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp, LOW);
}
else if(digit1==8) {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp, LOW);
}
else if(digit1==9) {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp, LOW);
}
}

Function-definition is not allowed here before '{' token

I have been working with this simple program trying to fix this error for way too long. I am working with an Arduino and I just want to make an easy temperature monitor to turn some switches on and off. I keep getting the error "Function-definition is not allowed here before '{' token." If someone who knows more than I do and can help me out, that would be great!
float temp;
void setup(){
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(7, INPUT);
pinMode(0, INPUT);
Serial.begin(9600);
}
void highHeat(){
temp = analogRead(0);
temp = (5.0*temp*100.0/1024.0);
if (temp > 79)
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(13, LOW);
}
if (temp < 78)
{
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(13, HIGH);
}
delay(10000);
}
void lowHeat(){
temp = analogRead(0);
temp = (5.0*temp*100.0/1024.0);
if (temp > 26)
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(13, LOW);
}
if (temp < 25)
{
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(13, HIGH);
}
delay(10000);
}
void loop(){
if (6 == HIGH)
{
delay(2000);
if (6 == HIGH)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
void loop(){
lowHeat();
}
}
if (6 == LOW)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
void loop(){
highHeat();
}
}
}
}
P.S. I've done some searching and found many posts with the same title, but they never seem to be relevant to my problem, so I just thought I would ask for a little help.
You have:
digitalWrite(13, LOW);
void loop(){
lowHeat();
}
The compiler is complaining about the void loop() there. You can't define a function in the middle of another one.

Resources