Is it possible to turn the build in LED solid "ON" on the ESP8266 ESP-01?
On the Arduino UNO REV.3 this code works, it sets the LED_BUILTIN to glow sold "ON":
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
}
On the ESP8266 ESP-01 this code works for blinking its built in LED:
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
}
But I can not get it to be just solid "ON".
Try this
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
}
Yes, it works the other way around. The LED will turn on with digitalWrite(LED_BUILTIN, LOW);.
Related
I want to communicate between 2 Pi Pico's using I2C. I want to do program these with the Arduino IDE. I have tried using Wire.h and some examples I found online. However, they don't seem to be able to connect to each other.
This is my Master code:
#include "Wire.h"
void setup() {
Wire.begin();
Serial.begin(9600);
bool setSDA(1);
bool setSCL(2);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
Wire.requestFrom(8, 6);
Serial.println("Waiting...");
while (Wire.available()) {
char c = Wire.read();
Serial.print(c); }
delay(500);
}
This is my slave code:
#include "Wire.h"
void setup() {
Wire.begin(8);
Wire.onRequest(requestEvent);
Serial.begin();
bool setSDA(1);
bool setSCL(2);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
delay(100);
Serial.println("Recieving...");
}
void requestEvent() {
Wire.write("hello ");
}
What am I doing wrong?
I'm here regarding the issue I'm having building my project which is IR sensor controlled car with a LCD screen. I have built only 2 projects before this one that I have coded and designed their circuits, hence, I'm fairly new to all this. I expected this car to go forward, turn left & right, and to stop. I first used the code to identify the key code of my IR remote for the buttons I want to use to control my project, then I wrote the code given below. But, whenever I use the buttons I have programmed, the project respond only once to the IR remote and then freezes and continues on. Suppose, If I click the button which I have programmed it to go forward, it starts going forward, but then it stops responding to other buttons. I've tried using higher voltage and current batter but that doesn't seem to help.
Here is the code:
// Setting up LCD Display Here.
#include<LiquidCrystal.h>
int RS = 13;
int E = 12;
int D4 = 11;
int D5 = 10;
int D6 = 6;
int D7 = 2;
LiquidCrystal lcd(RS,E,D4,D5,D6,D7);
// Setting up IR reciver sensor here.
#include<IRremote.h>
int IR_Reciver_Pin = A5;
IRrecv irrecv(IR_Reciver_Pin);
decode_results results;
// Setting up DC motor pins.
/* Motor A connections */
int enA = 9;
int in1 = 8;
int in2 = 7;
/* Motor B connections */
int enB = 3;
int in3 = 5;
int in4 = 4;
void setup() {
// Initiating LCD display here.
lcd.begin(16,2);
lcd.print("Welcome!");
// Initiating IR reciver sensor here.
irrecv.enableIRIn();
// Initiating Serial Monitor.
Serial.begin(9600);
// Initiating DC motors.
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Turning motors off - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop() {
// Reading IR remote value.
if(irrecv.decode(&results))
{
int value = results.value;
Serial.print(F("CODE: "));
Serial.println(results.value);
irrecv.resume();
}
// Code for providing 5V to L293D H-Brigde.
analogWrite(enA, 255);
analogWrite(enB, 255);
// Code for going forward.
if(results.value==3772778233)
{
lcd.clear();
lcd.print(F("Rolling forward"));
lcd.setCursor(0,2);
lcd.print(F("captain!"));
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
// Code for turning right.
if(results.value==3772794553)
{
lcd.clear();
lcd.print(F("Turning towards"));
lcd.setCursor(0,2);
lcd.print(F("right."));
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
// Code for turning left.
if(results.value==3772819033)
{
lcd.clear();
lcd.print(F("Turning towards"));
lcd.setCursor(0,2);
lcd.print(F("left."));
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
// Code for stoping.
if(results.value==3772782313)
{
lcd.clear();
lcd.print(F("Halting captain!"));
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
}
This is the circuit diagram.
At first glance, I would say that the problem is that your if statments in loop should be nested inside : if(irrecv.decode(&results)){}
So, your loop should look something like this:
void loop() {
analogWrite(enA, 255);
analogWrite(enB, 255);
while(!(irrecv.decode(&results))); //It waits until no button is pressed
if(irrecv.decode(&results))
{
int value = results.value;
Serial.print(F("CODE: "));
Serial.println(results.value);
// Code for going forward.
if(results.value==3772778233)
{
lcd.clear();
lcd.print(F("Rolling forward"));
lcd.setCursor(0,2);
lcd.print(F("captain!"));
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
// Code for turning right.
if(results.value==3772794553)
{
lcd.clear();
lcd.print(F("Turning towards"));
lcd.setCursor(0,2);
lcd.print(F("right."));
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
// Code for turning left.
if(results.value==3772819033)
{
lcd.clear();
lcd.print(F("Turning towards"));
lcd.setCursor(0,2);
lcd.print(F("left."));
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
// Code for stoping.
if(results.value==3772782313)
{
lcd.clear();
lcd.print(F("Halting captain!"));
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
irrecv.resume();
}
}
can i trigger a function in arduino with node-red?
i tried to research it before and i couldn't find any
my arduino code is
int motor1 = 2;
int motor2 = 3;
int motor3 = 4;
int motor4 = 5;
int motor5 = 6;
int motor6 = 7;
int motor7 = 8;
int motor8 = 9;
void setup() {
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(motor3, OUTPUT);
pinMode(motor4, OUTPUT);
pinMode(motor5, OUTPUT);
pinMode(motor6, OUTPUT);
pinMode(motor7, OUTPUT);
pinMode(motor8, OUTPUT);
}
void loop() {
yeetmotor1();
yeetmotor2();
yeetmotor3();
yeetmotor4();
}
void yeetmotor1(){
digitalWrite(motor1, HIGH);
digitalWrite(motor2, LOW);
delay(1000);
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
}
void yeetmotor2(){
digitalWrite(motor3, HIGH);
digitalWrite(motor4, LOW);
delay(1000);
digitalWrite(motor3, LOW);
digitalWrite(motor4, LOW);
}
void yeetmotor3(){
digitalWrite(motor5, HIGH);
digitalWrite(motor6, LOW);
delay(1000);
digitalWrite(motor5, LOW);
digitalWrite(motor6, LOW);
}
void yeetmotor4(){
digitalWrite(motor7, HIGH);
digitalWrite(motor8, LOW);
delay(1000);
digitalWrite(motor7, LOW);
digitalWrite(motor8, LOW);
}
If you have any clue for this please send help because i think it is possible to do it
Thank you for anying answering it
I am trying to run a for loop inside an if statement but it keeps repeating. I basically want pin 4 to blink 6 times when I press a button on pin 2. When z becomes a 6 in the for loop, the if statement makes it so that z is reset to 0 and the for loop restart all over again. Therefore the LED on pin 4 keeps blinking on and on. Anyone can help so that it blinks only 6 times? Here is the code:
int switchState = 0;
void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop()
{
switchState = digitalRead(2);
if (switchState == LOW)
{
digitalWrite(5, LOW);
digitalWrite(4, LOW);
}
else
{
digitalWrite(5, HIGH);
for (int z=0; z<6; z++)
{
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
delay(100);
}
}
}
Try out this:
void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop()
{
//Deactivate all leds
digitalWrite(5, LOW);
digitalWrite(4, LOW);
if (digitalRead(2) == HIGH) { //If the button is pressed...
digitalWrite(5, HIGH);
//blink
for (int z=0; z<6; z++)
{
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
delay(100);
}
while (digitalRead(2) == HIGH) { // Wait until release the button
delay(10);
}
}
}
My Code:
*int led = 13;
void setup(){
Serial.begin(9600);
pinMode(led, OUTPUT);
while (!Serial) {
//My code get stack here!
//it stay here looping on endlessly!
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
}
void loop() {
}*
So this is the problem. the simple program waiting for Serial and the while loop continue forever.
how to fix this. is it a known problem?
int led = 13;
void setup(){
Serial.begin(9600);
pinMode(led, OUTPUT);
while (!Serial1) {
//My code get stack here!
//it stay here looping on endlessly!
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
}
}
void loop() {
}
I think that is a missing bracket closing setup()
Your loop condition is wrong. If you want to wait for something to appear on the serial port then you need to change it to this:
while (Serial.available() == 0) {
Your code is fine, it looks like your serial port is not connecting. If I modify your code to watch a counter up to 5, and when the counter is 5 then myconnection is true, then !myconnection is false and the loop stops (watch it in Tools>Serial Monitor):
int led = 13;
int counter = 0;
boolean myconnection = false;
void setup(){
Serial.begin(9600);
pinMode(led, OUTPUT);
while (!myconnection) {
//My code get stack here!
//it stay here looping on endlessly!
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
//here's my debug stuff
counter++;
if (counter ==5 ){
myconnection = true;
}
Serial.println("counter: " + String(counter) + ", myconnection: " + String(myconnection));
}
}
void loop() {
}