Arduino code to make an led strip of 3 blink - arduino

I have an arduino board with an led strip with 3 led plugged into pin 1. a picture of the wiring is below. this is the code I used to attempt to lightup the led, with no luck:
#include <Adafruit_NeoPixel.h>
#define PIN 1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_KHZ800);
void setup() {
strip.begin();
strip.show();//Initialize all pixels to 'off'
strip.setbrightness(50);
forcint i=0; i<3;i++)
strip.setPixelColor(0,255,255,255);
strip.show();
}
void loop() {
for (int i=255;i>=0;i--){
lightColor(i,0,0);
delay(10);
i=i+2
}
}
any help will be aprecited, this is my first time using arduino

#include <Adafruit_NeoPixel.h>
#define PIN 13
Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_KHZ800);
void setup() {
strip.begin();
strip.show();//Initialize all pixels to 'off'
strip.setbrightness(50);
strip.setPixelColor(0,255,255,255);
strip.show();
}
void loop() {
for (int i=255;i>=0;i--){
lightColor(i,0,0);
delay(10);
}
delay(500);
}
With this code, LED will decrease RED channel until 0, wait 0'5 seconds and repeat.
I change your setup function by deleting a malformed for loop. And in loop() I added a delay and removed i=i+2 bacause I didn't understand its function. And finally, you must use another pin because PIN 1 is for serial use.

Related

Compilation error in Arduino water pump control program

#include <Adafruit_EEPROM_I2C.h>
#include <Adafruit_FRAM_I2C.h>
#include <Servo.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc; // create an instance of the RTC object
Servo myservo; // create an instance of the Servo object
const int servoPin = 9; // define the pin for the servo motor
const int pumpPin = 8; // define the pin for the DC water pump
void setup() {
Serial.begin(9600); // start the serial connection
myservo.attach(servoPin); // attach the servo to the servo pin
pinMode(pumpPin, OUTPUT); // set the pump pin as an output
Wire.begin(); // start the I2C communication
rtc.begin(); // start the RTC
}
void loop() {
DateTime now = rtc.now(); // get the current time from the RTC
// check if it is 7:00 or 12:00
if (now.hour() == 7 || now.hour() == 12) {
// move the servo to the "on" position
myservo.write(0);
delay(2000); // wait for 2 seconds
// turn on the DC water pump
digitalWrite(pumpPin, HIGH);
delay(10000); // wait for 10 seconds
// turn off the DC water pump
digitalWrite(pumpPin, LOW);
// move the servo to the "off" position
myservo.write(180);
}
delay(1000); // wait for 1 second before checking the time again
}
That is my program, but when I try to compile it the error reads #include <Adafruit_I2CDevice.h> Error compiling for board Arduino Uno. Can anyone help me please? I'm just a beginner.
Remove the first two lines, these ones:
#include <Adafruit_EEPROM_I2C.h>
#include <Adafruit_FRAM_I2C.h>
You don't use these libraries in your program, and as far as I know they are not intended for use with the Arduino Uno.

Arduino IRremote Send and Receive simultaneously

I'm currently working on a lasertag game with several weapons.
I would like to use one arduino nano in each weapon. It should be able to receive the IR-signals of the opponents as well as send IR-signals if a button is triggered.
So now there comes my problem:
I implemented an interrupt for the IR-receiver pin, so that an opponent's shot is always detected even when I'm shooting.
When the button is permanently pressed, the IR LED will shoot every 300 milliseconds (the send-function takes approximately 70ms and I implemented a delay of 230ms).
Unfortunately, the Nano won't detect any signal of the receiver in those 300ms.
However, if I disconnect the IR-LED everything seems to work perfectly.
Now I'm wondering, why the IR-LEDs connection has an effect on the functionality of my code.
Do you know any way I could solve this problem?
Here you can see the entire code I implemented:
#define IR_SEND_PIN 3
#define BUTTON_PIN 10
#define LED_PIN 12
#include <IRremote.hpp>
#include <Arduino.h>
uint8_t sAddress = 0;
uint8_t sCommand = 0x59;
uint8_t sRepeats = 0;
volatile uint8_t hitData;
void setup() {
IrSender.begin();
IrReceiver.begin(IR_RECEIVE_PIN);
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IR_RECEIVE_PIN), HIT, CHANGE);
}
void HIT() {
if (IrReceiver.decode()) {
hitData = IrReceiver.decodedIRData.command;
}
IrReceiver.resume();
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
IrSender.sendNEC(sAddress, sCommand, sRepeats);
delay(120);
}
if (hitData == sCommand) { // indicates received signal 0x59
hitData = 0x00;
IrReceiver.resume();
digitalWrite(LED_PIN, HIGH);
delay(8);
digitalWrite(LED_PIN, LOW);
}
}```

Arduino sleep while digital pin is HIGH

I want to make the Arduino Pro Mini run on a 3.7v (4.2v when fully charged) LI-Ion battery.
The project is I will use an IR sensor to control the relay. Based on the IR code received, I will toggle the relay digital output pin (HIGH or LOW). Initially, the arduino is set to deep sleep mode and when it receives an External Interrupt (pin 2 on pro-mini), it will process the IR code and switch on the relay.
//Interrupts using Arduino
//Circuit Digest
#include "LowPower.h"
#include <IRremote.h>
volatile int output = LOW;
int i = 0;
#define RECV_PIN 2
volatile boolean sleepEnabled = true;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
irrecv.enableIRIn();
pinMode(RECV_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(RECV_PIN), buttonPressed1, RISING); // function for creating external interrupts at pin2 on Rising (LOW to HIGH)
}
void loop()
{
Serial.println(i);
++i;
delay(1000);
output = LOW;
digitalWrite(13, output); //Turns LED ON or OFF depending upon output value
if (sleepEnabled == true) {
Serial.println("Going to sleep");
delay(1000);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}
delay(500);
readIR();
}
void buttonPressed1() //ISR function excutes when push button at pinD2 is pressed
{
sleepEnabled = false;
}
void readIR() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if (results.value == 0xff4ab5) {
sleepEnabled = true;
}
}
irrecv.resume(); // Receive the next value
}
When the pro-mini goes back to sleep, everything is turned off.
How can I make the pro-mini consume minimal power while the relay pin is HIGH ?

arduino user input to control on and off (with time)

I want to use bluetooth connection to control, how long something is on. So I read the Serial Input. If it is a number, I take the number and put it into a delay. After it is through, I write something and check again. If the Serial Read is not a number, it should turn off. in The problem is, the led keeps running. Do you see, what is my mistake?
#include <SoftwareSerial.h>
#define ledPin 13
#define rxPin 10
#define txPin 11
SoftwareSerial btSerial(rxPin, txPin);
int btData;
void setup() {
btSerial.begin(9600);
btSerial.println("bluetooth available");
pinMode(ledPin,OUTPUT);
serv.attach(3);
serv2.attach(5);
}
void loop() {
if (btSerial.available()){
btData = btSerial.read();
if(isDigit(btData)){
digitalWrite(ledPin,1);
btSerial.println("LED on Pin is on");
delay(btData*10);
}
else {
digitalWrite(ledPin,0);
btSerial.println("LED on Pin is off");
}
}
delay(100);
}
Try to use this:
#include <SoftwareSerial.h>
#define ledPin 13
#define rxPin 10
#define txPin 11
SoftwareSerial btSerial(rxPin, txPin);
int btData;
void setup() {
btSerial.begin(9600);
btSerial.println("bluetooth available");
pinMode(ledPin,OUTPUT);
serv.attach(3);
serv2.attach(5);
}
void loop() {
if (btSerial.available())
btData = btSerial.read();
if(isDigit(btData)){
digitalWrite(ledPin,1);
btSerial.println("LED on Pin is on");
delay(btData*10);
}
else {
digitalWrite(ledPin,0);
btSerial.println("LED on Pin is off");
}
delay(100);
}
And the reason is because the enabling and disabling was done only when there is serial data and if you put the if anywhere else it would be checked always.

Send IR values using infrared emitter led on Arduino

i have Arduino Mega and an IR Emitting LED and i want to send data "Hex Data" that i choose using this LED and i have tried the IRRemote Library and i have successfully used the IRrecv class, but when using IRsend i didn't get any signal and have tried to look at the led through the mobile camera
the IR Emitter Pin is PWM 3 and have connected it to 3.3V once and to 5V once
#include <IRremote.h>
IRsend irsend;
void setup()
{
Serial.begin(9600);
}
void loop() {
if (Serial.read() != -1) {
for (int i = 0; i < 3; i++) {
irsend.sendSony(0xa90, 12); // Sony TV power code
delay(40);
}
}
}
and for the receiver:
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
any help is appreciated :) Hiso
i Have looked at the IRRemote.cpp library you refereed to and in the header file you can see that each Arduino board have a unique PWM pin that is used to transmit infrared data so use PWM 9 it's assured to work on Arduino Mega

Resources