Arduino self shutdown using relay not working - arduino

I'm working on a project that need to shutdown arduino main power (not sleep) to save battery.
Follow this tutorial:
zola lab
Here is Zola scheme (i choose the relay option):
And here what i have done:
The code:
// www.zolalab.com.br - By Eduardo Zola - 2016
void setup()
{
pinMode(7,OUTPUT); // Relay Signal Pin
digitalWrite(7,HIGH);
pinMode(8,OUTPUT); // buzzer & LED (start with buzzer on)
digitalWrite(8,HIGH);
pinMode(13,OUTPUT); // LED built-in Arduino
digitalWrite(13,HIGH);
delay(50);
digitalWrite(8,LOW); // turn off buzzer
delay(5000); // wait for 5 seconds to shutdown the circuit
for(int i = 0;i<3;i++){
digitalWrite(8,HIGH);delay(80);digitalWrite(8,LOW);delay(600);
}; // beeps
digitalWrite(8,HIGH);delay(1000);digitalWrite(8,LOW);
digitalWrite(7,LOW); // shutdown the circuit
}
void loop()
{
}
My main power 5v in breadboard come at the top left.
The relay is different. My relay is this:
Problem is, when i click switch button in the breadboard, nothing happened.
Any help would be very appreciated.

The breadboards like yours usually have power rails separated in the middle. On a photo of your setup it looks like you connected your power supply to the upper half of the board, and reset of the circuit to the lower. Try connecting everything on the same half, or use jumpers to connect power rails.

Found the solution.
Change the digitalWrite from HIGH to LOW and LOW to HIGH for pin 7
void setup()
{
pinMode(7,OUTPUT); // Relay Signal Pin
digitalWrite(7,LOW); // <-- change this
...
...
digitalWrite(7,HIGH); // shutdown the circuit <-- change this too
}
void loop()
{
}
Hope this help others for having same relay.

Related

Can't see Serial.print() outputs in Visual Studio Code from Arduino device (ESP8266)

I can't see any Serial.print() outputs in Visual Studio Code from my Arduino device (an ESP8266 in this case). I was expecting to see it on the Debug Console. Do I have something configured incorrectly?
I know my code is working as the LED is flashing but I'm not seeing any output anywhere.
Here's my code:
#include <Arduino.h>
void setup()
{
Serial.begin(9600); // EDIT: added this line
Serial.println("Setup...");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
Serial.print("On!");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
Serial.print("Off!");
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
I am using this board:
https://www.waveshare.com/wiki/e-Paper_ESP8266_Driver_Board
Here is my platformio.ini file:
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
; Custom Serial Monitor port
monitor_port = COM4
; Custom Serial Monitor speed (baud rate)
monitor_speed = 9600
Near the bottom right of the VS Code screen is a little plug icon. Click that to open the serial monitor.
Set serial port baud rate in setup() by adding this code:
Serial.begin(SERIAL_BAUD_RATE);
For example:
Serial.begin(9600);
Finaly in serial port monitor set baud rate

5volt Arduino Pro Mini Not Able to Drive 5 Volt actuator But The same work perfectly Done by Arduino Uno

I want to drive an actuator from 5 volt Arduino pro mini and it's control by Bluetooth signal from mobile .
circuit detail:
1)Arduino Promini 5 volt
2) Hc05 Bluetooth Module
3)5volt Actuator
I was powering 11.8 Volt directly to the RAW pin of Arduino pro mini .
When It was receiving 1 or 0 it is unable to control the actuator and after connecting the data pin of actuator with pin 13 of arduino pro-mini the flash light continuously blinking
But Above same operation perfectly done by Arduino Uno Board. So is there any possible to control the actuator using arduino promini over bluetooth signal. Reason behind I am using Arduino pro mini instead of Arduino Uno it's took less space.
Arduino Code:
#include<SoftwareSerial.h>
SoftwareSerial BT(2, 3);
#include <Servo.h>
Servo myservo;
int ServoPin =13;
void setup()
{
Serial.begin(9600);
myservo.attach(ServoPin);
pinMode(ServoPin, OUTPUT);
digitalWrite(ServoPin, LOW);
myservo.write(40);
// set digital pin to control as an output
pinMode(9, OUTPUT);
// set the data rate for the SoftwareSerial port
BT.begin(9600);
// Send test message to other device
BT.println("Hello from Arduino");
}
char a; // stores incoming character from other device
void loop()
{
if (BT.available())// if text arrived in from BT serial...
{
a=(BT.read());
Serial.println(a);
if (a=='1')
{
digitalWrite(9, HIGH);
BT.println(" You have to turn oN the LED/servo| I got the command : 1 ") ;
Serial.println("I got the command :");
Serial .println(a);
myservo.write(180);
a=' ';
}
else if (a=='0')
{
myservo.write(40);
digitalWrite(9, LOW);
BT.println(" You have to turn Off the LED!/servo| I got the command :0");
Serial.println("I got the command :");
Serial .println(a);
a=' ';
}
}
}
i think the issue is with the current. first check how much power is required to drive the actuator. if the current is insufficient you can use ULN2003 it's a relay driver ic but you can use it for your ckt if you are less in space you can use single darlington pair.

master slave communication between two attiny 85 IC

Is it possible to communicate between two ATtiny85? I can use my Arduino to communicate with ATtiny85 by using Arduino Uno as the master and ATtiny85 as a slave. But I want to use one ATtiny85 as the master and one as a slave. Is this possible ?
I am not able to understand the examples given in TinyWireM library. I want a simple master and slave code for communication. For example, master should ask for 1 integer value and slave should reply.
My slave code :
#define I2C_SLAVE_ADDRESS 0x14 // Address of the slave
#include <TinyWireS.h>
int i=0;
void setup()
{
TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network
TinyWireS.onRequest(requestEvent);
}
void loop()
{
TinyWireS_stop_check();
}
void requestEvent()
{
if(i==1000)
{
TinyWireS.send(1);
i=0;
}
else
i++;
}
My master code
#include <TinyWireM.h>
#define DS1621_ADDR 0x14
void setup()
{
TinyWireM.begin();
pinMode(4, OUTPUT);
}
void loop()
{
TinyWireM.requestFrom(DS1621_ADDR,4); // Request 1 byte from slave
int tempC = TinyWireM.receive();
if(tempC)
{
digitalWrite(4, HIGH);
delay(1000); // wait for a second
digitalWrite(4, LOW);
delay(1000); // wait for a second
}
if(tempC>1)
{
digitalWrite(4, HIGH);
delay(1000); // wait for a second
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
I tried the above code but still I cannot see the LED blinking. But if I keep slave code as it is and use the following master code on an Arduino then everything works fine.
Arduino Uno code as master.
#include <Wire.h>
float i1=-1, i2=-1;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(4, 1); // request 1 byte from slave address 4
while(Wire.available()) // slave may send less than requested
{
i1 = Wire.read(); // receive a byte as character
Serial.println(i1); // print the character
}
}
connection is and connections are SDA to SCL pins
pin 5 of master attiny85 - pin 7 of slave attiny85
pin 7 of slave attiny85 - pin 5 of master attiny85
I also tried by no cross connecting them. example and connections are SDA to SDA pins
pin 5 of master attiny85 - pin 5 of slave attiny85
pin 7 of slave attiny85 - pin 7 of master attiny85
but still no success.
Yes, it is possible to use 1 ATtiny85 as a master, and another as a slave. The TinyWireM and TinyWireS libraries are both well-written and easy to use.
Handling a request and sending back bytes is as simple as setting the onRequest slave read event handler to a function of your choice that sends the correct data back. There are examples of this in the TinyWireS library.
Did you use the pull-up resistor for both, the SDA and SCL? They are important for the I2C protocol.
FYI: The logic '0' on the either bus is set by device driving actual '0' on the pin. On the other hand, the logic '1' is set on the bus by putting the device pin in the high impedance, in case on the ATtiny, it means setting pin into INPUT direction. When the both, the master and slave set pins to hiZ, the pull-up resistor pulls the voltage on the bus to value representing logic '1'. This solution allows avoiding contention on bi-directional bus (one device driving '1' and second driving '0') than can lead to short-circuit and damaging devices. So, if you don't use the pull-up resistor, the bus will be left floating whenever logic '1' is driven and it will lead to protocol errors.

CANbus simulation for Automotive purpose

i explain a bit...
I repair Electric powered steering systems for cars, especially Fiat/Alfa/Lancya (Delphi manufacturers) and i'm in need of making some tool to test these reparations, i mean just turning it on for example.
I have researched during some time, and i figured i need Can-bus signals to be simulated as the eps ECU is receiving ignition packets from CAN, here i go..
I need to know what way i could Read/Send CAN packets from/to BUS, i mean what tool or anything else. I have been trying with Arduino UNO + Sparkfun Shield, but i dont get any results, when everything connected, my serial console isnt sniffing any packets, i have connected all correctly i think, tried different bitRates, changed Arduino boards and shield, tried many different examples, i invested lots of hours with no profit... i was using Seat Ibiza 2010 for I+D, connected CAN-H AND CAN-L on OBD PORT, in the CAN lines from radio,etc...
Any idea of what could be wrong is welcome, as new method to make my project.. Thanks in advance!!
Info:
https://dl.dropboxusercontent.com/u/47864432/arduino/IMG_9358.JPG
https://dl.dropboxusercontent.com/u/47864432/canbus/LIBRARYS_USED.rar
There are two potential issues here:
H/W problem
CAN bus library problem
The first step is try loopback test. If all is OK, try CAN bus from any car OBD port, the speed should be 500Kb.
This one tries a couple of bus speeds -- works with sparkfun canbus shield:
#include <SPI.h>
#include <SD.h>
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
const int chipSelect = 9;
File dataFile;
void setup() {
// put your setup code here, to run once:
pinMode(chipSelect, OUTPUT);
Serial.begin(115200); // For debug use
Serial.println("CAN Read - Testing receival of CAN Bus message");
delay(1000);
if (Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 500k");
else if (Canbus.init(CANSPEED_250)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 250k");
else if (Canbus.init(CANSPEED_125)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 125k");
else
Serial.println("Can't init CAN");
delay(1000);
if (!SD.begin(chipSelect)) {
Serial.println("uSD card failed to initialize, or is not present");
return;
}
else {
Serial.println("uSD card initialized.");
delay(1500);
}
dataFile = SD.open("caninfo.txt", FILE_WRITE);
}
void loop() {
tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
if (dataFile) {
int timeStamp = millis();
//write to uSD card
dataFile.print(timeStamp);
dataFile.print("ID: ");
dataFile.print(message.id, HEX);
dataFile.print(", ");
dataFile.print("Data: ");
dataFile.print(message.header.length, DEC);
for (int i = 0; i < message.header.length; i++)
{
dataFile.print(message.data[i], HEX);
dataFile.print(" ");
}
dataFile.println("");
Serial.println("Writing to SD");
}
else
{
Serial.println("Problem writing to SD");
}
}
}
}
If you want to communicate via CAN with Steering controller for example for an OEM like Delhpi .. this is not possible as the ECU (ELectronic control units) in the communication network are secured and the CAN protocol software decides who can participate and who can't.
As a tester tool you can read the trouble codes but you can't hack it to simulate the Ignition signal etc...

Arduinio sd on Ethernet shield not working at all

I am new to Arduino, and I have an ethernet shield with an SD socket on top, but it not seems to be working.
I am just trying to run a simple sketch taken from the SD libraries example to get infos about the card, but the "card.init(SPI_HALF_SPEED, chipSelect)" part always fails.
I have set the ChipSelect pin to 4, and set pin 10 to output, still nothing.
My code:
#include <SD.h>
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("\nInitializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT); // change this to 53 on a mega
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
}
void loop(void) {
}
What I get:
Initializing SD card...initialization failed. Things to check:
* is a card is inserted?
* Is your wiring correct?
* did you change the chipSelect pin to match your shield or module?
I am using Arduino Uno R3, Ethernet Shield (not the official one).
I have tried with several SD cards: SD/SDHC, 2/4/16 Gb, Sandisk/Kingston, formatted with FAT16/FAT32
I am afraid something is bad with the shield itself (though the ethernet part is working). How can I identify the source of the problem? Please Help!
Check here:
https://electronics.stackexchange.com/questions/67212/how-to-avoid-sd-card-and-w1500-spi-mixup-on-the-ethernet-shield/93868#93868
short overview of the answer from the link above:
#define SS_SD_CARD 4
#define SS_ETHERNET 10
digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
digitalWrite(SS_ETHERNET, HIGH); // Ethernet not active
digitalWrite(SS_SD_CARD, LOW); // SD Card ACTIVE
//do SD-Card stuff here
digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
digitalWrite(SS_ETHERNET, LOW); // Ethernet ACTIVE
//do Ethernet stuff here
if you have a Arduino Ethernet / SD Shield with the Wiznet 5100 Chip on it, you have exactly that known W5100 bug - as my Shield has. There are more informations about that bug by googling it.
When you connect this shield with the arduino the ethernet function is active and will not work if a sd-card is inserted in the slot. By using one of the Ethernet Examples from the standard library you will always get a DHCP failure (Failed to configure Ethernet using DHCP). By removing the SD-Card and restarting arduino (reset) it will work.
When you have to use both functions as I like to do you will have to struggle within the code in order to turn ethernet off and sd on and vice versa.
pinMode(4, OUTPUT);
or to be correct
pinMode(chipSelect,OUTPUT);
Add this in the setting pin 10. hope this helps.
Some times in life it is the little things that mess us up.
Put the following line of code after you set the pin 10 to output:
digitalWrite(10, High);
This should do the trick.
FYI for anyone experiencing similar issues, i.e. using the Ethernet shield SD card and essentially the Arduino website SD card sample code and having inexplicable issues initializing the SD card. The above solution allowed the initialization for me.
I ran your code and fixed it by initializing SD.begin() before the line Serial.print("\n Initializing SD card...");
Something like this:
SD.begin();
Serial.print("\nInitializing SD card...");

Resources