Questions tagged [code-review]
Code review is systematic examination of your Arduino sketch. It is intended to find and fix mistakes overlooked in the initial development phase, improving both the overall quality of software and the developers' skills.
253 questions
11
votes
1
answer
276
views
Cloud function getting stopped Parse.com in loop when calling from Arduino-yun
I have created a cloud function using the Parse.com Javascript SDK and I am calling those functions from Arduino. Following is code for the hello function:
Parse.Cloud.define("hello", function(...
9
votes
3
answers
2k
views
delay(time); vs if(millis()-previous>time); and drift
Going through an old project, I had code on two Arduino Due that looked like this
void loop()
{
foo();
delay(time);
}
taking to heart the majority of literature on using delay(); I recoded this ...
5
votes
3
answers
2k
views
How do I make another action repeat inside a loop?
So, I've just started programming Arduino (and also in general), so I'm doing basic things, like switching on and off LED's.
I've made them light in a sequence and then turning them off (in the same ...
5
votes
2
answers
7k
views
DC Motor Speed Measurement using Rotary Encoder
I have written the following code to measure the speed of a unidirectional DC Motor.I have attempted to measure the time between successive interrupts in order to calculate speed.
boolean check;
...
4
votes
2
answers
2k
views
How to move a servo quickly and without delay function
Im trying to move a servo from one place to another while using the typical for loop you find in the servo's library example:
int lightON = 180;
int lightOFF = 90;
for (pos1 = lightOFF; pos1 <= ...
4
votes
1
answer
2k
views
NRF24L01 only receiving zeros
I'm attempting to transmit very simple data across some NRF24l01 modules for testing purposes, and I've been following a YouTube guide.
Here is my code:
Trasmitter:
#include "RF24.h"
#include <...
4
votes
1
answer
312
views
Working with multiplexers for constant voltage output
I'm working on creating a circuit where I'm trying to have the ability to switch multiple strands of LED rope on and off at a time using an Arduino and a multiplexer.
With my current configuration, ...
4
votes
1
answer
1k
views
Arduino Uno as keyboard
I am trying to make Arduino Uno to act as a keyboard. I have successfully flashed the USB-HID firmware in it using this link also and programmed it like this.
uint8_t buf[8] = {
0
};
int inpin1 = 7;...
3
votes
1
answer
738
views
Why is this looping?
I am trying to do something very simple. I want the LED to fade from full brightness to off. This works... However, the LED turns back on to full brightness and fades again, in a loop. I am not ...
3
votes
3
answers
3k
views
Variable declaration inside main loop
In the past I declared variables inside the main loop which worked just fine.
In a new project I did the same:
void loop(void)
{
uint8_t counter;
....
if (buttonPress)
counter = 0;...
3
votes
3
answers
2k
views
How to correctly use functions that return pointers to multiple typedef'ed types in Arduino IDE?
I have a program that typedef's two structs. Each one has a corresponding function that returns a pointer to it....
typedef struct {
int x1;
} x;
x *a;
x *f(void) {
return a;
}
typedef ...
3
votes
1
answer
786
views
How do I use a transmitter and receiver to send string messages conditionally to a receiver?
I'm working on a project to build a plant monitor that works from the outside with Arduino that picks up light and water values from it's environment then uses a nRF24L01 with an antenna and I've come ...
3
votes
2
answers
307
views
How to move a servo with a function
Im currently moving a servo from one side to another by using the typical for loop like this:
int lightON = 180;
int lightOFF = 90;
if (buttonState == HIGH) {
digitalWrite(LED, HIGH);
for (pos1 =...
3
votes
1
answer
139
views
My Arduino freezes if power removed from the HMI
I have an Arduino (Pro Mini) connected to an HMI display over serial. When the user pushes a button on the HMI screen, it activates a relay attached to one of the digital pins on the Arduino.
For ...
3
votes
5
answers
14k
views
Controlling Servo Motors with push button. Problem though
I have this setup where I have and Arduino Uno, a mini servo motor, and a pushbutton. I use a single pushbutton to control the servo motor to go to one position, then push it again to go back. It ...
3
votes
0
answers
517
views
Integration of MAX30100 and DS18B20 Thermal Probe Integration
This is for my final year project that I have been tasked with designing a patient monitoring system. However, during the last stretch of model prototyping, I am experiencing issues with my MAX30100 ...
3
votes
0
answers
3k
views
Encoder + Bounce2 Library
I am working towards debouncing my keyes rotary encoder using the Bounce2 library found here ( https://github.com/thomasfredericks/Bounce2 ).
I believe the problem lies in my code as there isn't much ...
2
votes
2
answers
314
views
Unwanted ghosting with charlieplexed LEDs
I have a very simple PCB that uses 3 GPIO on a ATtiny85 to control 6 LEDs using charlieplexing.
When I try to program certain patterns of lit LEDs (pseudo PWM) I get some LEDs lighting dimly when they ...
2
votes
1
answer
1k
views
Measure Vcc on ATtiny13a?
I am trying to figure out if I can measure the Vcc of attiny13a, but the code I use for arduino's and attiny85 does not work. This is where I got the code from. I know that it works by using the 1.1v ...
2
votes
2
answers
15k
views
Getting error ets jan 8 2013,rst cause:4,boot mode(1,6) wdt reset
I'm working on a project to send ultrasonic sensor data to my webserver. For that I'm using ESP8266 WiFi module, 3.3V regulator IC by giving input volt of 5v from aduino uno.
I successfully uploaded ...
2
votes
2
answers
1k
views
IR Remote code not activating ON/OFF states
The code below is for turning RGB lights on/off. The connections are as indicated in pin numbers. I found the resulting value of the buttons of the remote but when I used them in code it is not ...
2
votes
3
answers
509
views
Why do I get a compiler error when I'm pretty sure I have such method?
Code
(I've omitted much of the code, and left just the outline and code probably relating to the error.)
SelfDrivingCar.ino
#include "JKMain.h"
void setup() { JKMain::setup(); }
void loop() { ...
2
votes
2
answers
471
views
Controlling two AC devices, device turning on incorrectly
I am making use of the code below to control the speed of an AC fan and the intensity of an AC Lamp with an Uno.
The problem I am having is that, when I set the lamp intensity to low or medium, the ...
2
votes
1
answer
148
views
Ramping servo motor taking longer than calculated
I'm learning how to code a "BOE Shield bot" with a partner at my university (first year). To clarify for those that do not know: a BOE Shield bot is a small robot equipped with 2 servo ...
2
votes
1
answer
160
views
File created, but not logging data
I am starting using Arduino and have very little to none experience coding. However, I have managed to code and understand how it works.
The problem that I have is that I am unable to log (record) ...
2
votes
1
answer
1k
views
ESP8266 Webserver ESP8266WebServer variable html page (not as one const char)
The aim is to display a non-static html page depending on some variable condition.
The code I created hast the problem, that the esp8266 is ressetting in the moment I request the page.
const char ...
2
votes
2
answers
538
views
Turning a motor on and a led at the same time for a given time period
I need help with this code, I want to have a motor turn on for a given time and at the same time have an led light up to indicate it is on which will also turn of once the motor has stopped. It is ...
2
votes
2
answers
704
views
How do you make an Arduino count down timer?
I want to make a countdown timer with a LilyPad Arduino for 3 seconds with red (1 second), then orange(1 second), then yellow (1 second), then green (3 seconds), all being triggered by a button. I ...
2
votes
1
answer
379
views
Making an automated watering system with Arduino
I am trying to make an automated watering system using an Arduino.
Here is my wiring diagram:
And here is my circuit wired up:
Here is the code that I'm using with Arduino. The code seems alright ...
2
votes
2
answers
152
views
How to get 2 loop functions to cooperate?
I have a OLED SSD1306 & DS3231 RTC, 2 buttons to set the time & date. My project is to display a scrolling text at the top of the OLED, the RTC time in the middle, the day & date on the ...
2
votes
1
answer
104
views
Thermocouple and multimeter
I've put together this script that should allow my Arduino Mega to be show thermocouple readings on the serial monitor, whilst also showing readings of voltage and ohms across a given component. I'd ...
2
votes
1
answer
341
views
Why won't this code play a converted wav2c header file through an Arduino to my speaker?
I used this converter wav2c to convert a .wav file to a C that I can put in a header file. I was able to put converted audio into the h file but the program where I reference it does not seem to be ...
2
votes
2
answers
117
views
arduino LCD help
I am trying to create smart clock with alarm using an Arduino Uno.
My problem is when I set the alarm, I can't set the alarm again. Every time I must power off my Arduino and then power on in order ...
2
votes
2
answers
13k
views
Arduino Mega 2560 interrupt pins and port mapping with rotary encoder
I am trying to use port manipulation in interrupts to read a rotary encoder. I found code for a Uno, so the port call for pins 2 and 3 are different. I think on the Mega they are PORTH3 and PORTH4 ...
2
votes
1
answer
335
views
Is setting clock divider worth changing on delay() to save power?
Along all the "advanced" methods described in this article, does simple method as downscaling processor while delay makes a difference on power consumption? How much time does the clock alternation ...
2
votes
2
answers
755
views
Serial - Send data to Arduino while Arduino sending data
Arduino send data to PC each iteration. When I'm trying to send data to Arduino while receiving data from it, it takes too long. Serial.available() returns false even I sent data from PC. But if I add ...
2
votes
1
answer
1k
views
Results for GP2Y1010AU0F Dust Sensor
I am using Dust Sensor GP2Y1010AU0F
I downloaded the code from the manufacturer here:
http://www.waveshare.com/wiki/Dust_Sensor
/**********************************************************************...
2
votes
1
answer
115
views
Code for a load cycler seems to be stuck
I am trying to make a battery load cycler to charge and discharge a battery repeatedly for a certain amount of cycles and here is my code:
bool in_charge_mode;
int cycles = 0;
float cutoffvoltage = 2....
2
votes
0
answers
88
views
Am I maximising my A0 readout rate with this peak-detection code?
I have a pulse going into A0 on a Nano, and want to detect the peak voltage. With low-pass filtering to slow down the input pulse I'm still reading marginally too slow.
The code overall inhibits a ...
2
votes
0
answers
3k
views
Node MCU code is stuck in while (WiFi.status() != WL_CONNECTED) [closed]
I am using the Node MCu V3 board ESP8266MOD
Board Manager Version: 2.7.4
Arduino IDE: 1.8.12
My code is stuck in the while (WiFi.status() != WL_CONNECTED)
Here is code:
#include <ESP8266WiFi.h> ...
2
votes
0
answers
192
views
Please help with my tinkercad code. Debouncing stopwatch with lcd
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ssPin = 8;
int resetPin = 9;
bool cntrRunning = false;
int sec = 0;
int min = 0;
double currentMillis;
void setup()
{
...
2
votes
0
answers
863
views
How to Adjust MQ131 Sensor?
The problem
Hey. I'm trying to use the sensor Mq131 to measure some ozone data in a closed environment, but I'm having some bad time to adjust the trim in the sensor and get results in ppb. By ...
2
votes
0
answers
420
views
Error compiling for board Arduino Nano 33 BLE
I am trying to use pulse sensor with Arduino Nano 33 BLE sense, but when I verify it, it shows Error compiling for board Arduino Nano 33 BLE. The code is from the pulse sensor website. The code works ...
2
votes
0
answers
149
views
Help with code for changing motor speed depending on MPU6050 angles read
I have been trying to create code where my MPU6050 is constantly reading the angle it is at and based on that angle, increase or decrease the motor speed. For example the motor will be off when the ...
2
votes
0
answers
2k
views
Sending data from webserver to Arduino
Hello Arduino enthusiasts! I've been working on a keypad lock system for school lately and I need some advice.Basically, my code checks if the entered passcode is the same than a predefined passcode ...
2
votes
1
answer
789
views
Using a keypad to play an audio file on Arduino Mega and Adafruit VS1053?
I am trying to use a keypad to trigger an audio file using an Arduino Mega and Adafruit VS1053 Music Maker. I have gotten the music files to play independently, and when the correct number is entered ...
2
votes
0
answers
339
views
Motor shield code [closed]
I am working on a project using an Arduino Uno and a motor driver shield to move a car with an IRremote. But the vehicle is only moving forward and backward. I want it to move left and right. Kindly ...
2
votes
2
answers
841
views
Problem with measuring vibrations (Arduino UNO + step motor + accelerometer)
I'm trying to measure vibrations of the motor's shaft that is oscillating due to an eccentric load. For that, I am using the MPU 6050 6 axis accelerometer. The motor is a NEMA 17 stepper, connected to ...
2
votes
0
answers
2k
views
Arduino Uno doesn't work as Manchester code receiver
I'm sending some data from ATTINY85 to Arduino UNO using 433Mhz modules. Coding is Manchester using Manchester.h library from here.
Transmitting data works perfectly, 433 receiver gets data alright.
...
1
vote
1
answer
1k
views
Multiple Wire.write() not working for Arduino Nano I2C
Code for Master
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Wire.beginTransmission(9);
Wire.write('c');
Serial....