Please fix this to blink on pin 8 #define PIN PB0 void setup() { pinMode(PIN, OUTPUT); }…
- User
Please fix this to blink on pin 8 #define PIN PB0
void setup() { pinMode(PIN, OUTPUT); }
void loop() { digitalWrite(PIN, HIGH); delay(1000); // Wait for 1000 millisecond(s) digitalWrite(PIN, LOW); delay(1000); // Wait for 1000 millisecond(s) }
- Assistant
The issue is that
PB0corresponds to Arduino digital pin 8 on some boards, but it's better and more portable to definePINas the actual Arduino pin number (8), to avoid confusion.So just change:
#define PIN PB0to
#define PIN 8Here's your fixed code:
#define PIN 8 void setup() { pinMode(PIN, OUTPUT); } void loop() { digitalWrite(PIN, HIGH); delay(1000); // Wait for 1000 millisecond(s) digitalWrite(PIN, LOW); delay(1000); // Wait for 1000 millisecond(s) }This will blink the onboard LED (or an external LED connected to pin 8) every second.
- User
thanks
- Assistant
You’re welcome! If you have any more questions or need further help, feel free to ask. Happy coding! 😊
- User
how to connect a mosfet to use as a relay ? what is best between N and P version ?
- Assistant
- User
ok, take the n channel option, with flyback protection, and add an emergency stop (NC switch)
- Assistant
- User
great, the load is the coil of a contactor
- Assistant
- User
please draw better schematics
- Assistant
- User
link all elements in the schematics and fix the nc switch
- Assistant
- User
still not good with nc switch
- Assistant
- User
thanks
- Assistant
You’re very welcome! 😊 If you have any more questions or need help with your project, just ask. Good luck with your contactor control and stay safe! 🚦⚡️
- User
how to wire a led to a 24V source ?
- Assistant
To wire an LED to a 24V source safely, you need to use a current-limiting resistor in series with the LED to prevent it from burning out.
Why do you need a resistor?
- LEDs have a forward voltage ((V_F)) of about 1.8–3.3V (depending on color and type).
- Directly connecting the LED to 24V would cause excessive current to flow, damaging the LED instantly.
- The resistor limits current to a safe value.
- User
how to waste less power ?
- Assistant