Hi everyone,
So I am attempting to create a room occupancy monitor, using two motion sensors and an arduino nano-every (ATMEGA4809). I then want to send the occupancy of the room as an integer to Max MSP through serial.
I'm somewhat new to this and am having trouble uploading my code to the board. The code compiles no problem (although I'm sure its littered with errors I hope to troubleshoot later), but gives the following error message when uploading: "avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board. See https://support.arduino.cc/hc/en-us/sections/360003198300 for suggestions."
I've attached my code below.
Any help regarding any of this would be wonderful.
Thank you,
Kieran
int maxPeople = 5; // maximum number of people allowed before the alarm goes off
int sensitivity = 5; //lower values will make it more sensitive and higher values will make it less sensitive
//---------------------------------------------------
int currentPeople = 0;
int sensor1[] = {4,5};
int sensor2[] = {6,7};
int sensor1Initial;
int sensor2Initial;
String sequence = "";
int timeoutCounter = 0;
void setup() {
//Setup code
Serial.begin(9600);
delay(500);
sensor1Initial = measureDistance(sensor1);
sensor2Initial = measureDistance(sensor2);
}
void loop() {
//Read ultrasonic sensors
int sensor1Val = measureDistance(sensor1);
int sensor2Val = measureDistance(sensor2);
//Process the data
if(sensor1Val < sensor1Initial - 30 && sequence.charAt(0) != '1'){
sequence += "1";
}else if(sensor2Val < sensor2Initial - 30 && sequence.charAt(0) != '2'){
sequence += "2";
}
if(sequence.equals("12")){
currentPeople++;
sequence="";
delay(550);
}else if(sequence.equals("21") && currentPeople > 0){
currentPeople--;
sequence="";
delay(550);
}
//Resets the sequence if it is invalid or timeouts
if(sequence.length() > 2 || sequence.equals("11") || sequence.equals("22") || timeoutCounter > 200){
sequence="";
}
if(sequence.length() == 1){ //
timeoutCounter++;
}else{
timeoutCounter=0;
}
//Print values to serial
Serial.print("Seq: ");
Serial.print(sequence);
Serial.print(" S1: ");
Serial.print(sensor1Val);
Serial.print(" S2: ");
Serial.println(sensor2Val);
/*If the number of people is too high, trigger the buzzer
if(currentPeople > maxPeople){
tone(buzzer, 1700);
}else{
noTone(buzzer);
}
*/
}
//Returns the distance of the ultrasonic sensor that is passed in
//a[0] = echo, a[1] = trig
int measureDistance(int a[]) {
pinMode(a[1], OUTPUT);
digitalWrite(a[1], LOW);
delayMicroseconds(2);
digitalWrite(a[1], HIGH);
delayMicroseconds(10);
digitalWrite(a[1], LOW);
pinMode(a[0], INPUT);
long duration = pulseIn(a[0], HIGH, 100000);
return duration / 29 / 2;
Serial.println(currentPeople);
}