Notifications
Clear all

Arduino output voltage

17 Posts
4 Users
0 Reactions
2,389 Views
The apprentice
(@the-apprentice)
Member
Joined: 2 years ago
Posts: 75
Topic starter  

Good day everyone

I'm having problems with the output from my Arduino. I'm using the IRF520 mosfet module board and once I load the program. I only get 3v from the Arduino. There are 6 modules in my project. The 3v will not switch the mosfet. How can I change the voltage? I looked at the video from the workshop (Arduino High-Current Interfacing - Transistors & MOSFETs) using the same module and it works great. Thus I'm thinking it is the code? I'm not a coder, hopping someone will help. 

This is a simple quiz game controller I'm trying to built. Took the code from alastaira

// CONSTANTS
const int numPlayers = 6; // Number of players
const int buttonPins[numPlayers] = {A0, A1, A2, A3, A4, A5}; // Pins connected to player buttons
const int ledPins[numPlayers] = {4, 5, 6, 7, 8, 9}; // Pins connected to player LEDs
const int correctButtonPin = 3; // Pin connected to the button for correct answer
const int wrongButtonPin = 12; // Pin connected to the button for wrong answer



// GLOBALS
// If, and which, player has buzzed in
int8_t playerWhoBuzzed = -1;
// Array to track whether each player is active
bool playerActive[numPlayers] = {true, true, true, true, true, true };
int8_t playerScore[numPlayers] = {0, 0, 0, 0, 0, 0 };



void setup() {
  // Initialise a serial connection for debuggin
  Serial.begin(115200);
  Serial.println(__FILE__ __DATE__);


  // Configure pins
  for (int i=0; i<numPlayers; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP);
    pinMode(ledPins[i], OUTPUT);
  }
  pinMode(correctButtonPin, INPUT_PULLUP);
  pinMode(wrongButtonPin, INPUT_PULLUP);


}


void loop() {
  // We check for reset on every loop
  if(digitalRead(correctButtonPin) == LOW) {
    while(digitalRead(correctButtonPin) == LOW) { delay(100);}
    Serial.println("Reactivating all players");
    for (int i=0; i<numPlayers; i++) {
        activatePlayer(i);
      }
  }


  // Check if any player buzzes in
  for (int i = 0; i < numPlayers; i++) {
    // Light up the player's button if they are active
    digitalWrite(ledPins[i], playerActive[i] ? HIGH : LOW);
    // If an active player presses their button
    if (digitalRead(buttonPins[i]) == LOW && playerActive[i]) {
      Serial.print("Player ");
      Serial.print(i+1);
      Serial.println(" buzzed in");
      playerWhoBuzzed = i;
      break;
    }
  }
  // If a player has buzzed in, indicate it and play a sound
  if (playerWhoBuzzed != -1) {


    // Light up only the player who buzzed's LED
    for (int i=0; i<numPlayers; i++) {
      digitalWrite(ledPins[i], (playerWhoBuzzed == i));
    }


    // Wait for the host to confirm whether the answer is correct or not
    bool isAnswerCorrect = waitForHostInput();


    // If the answer is incorrect
    if (!isAnswerCorrect) {
      // Play this player's buzz SFX
     
      // Deduct a point for buzzing in incorrectly
      playerScore[playerWhoBuzzed]--;
      // Lock out this player from answering again
      Serial.print("INCORRECT. Deactivating player ");
      Serial.println(playerWhoBuzzed+1);
      deactivatePlayer(playerWhoBuzzed);


    }
    // If correct
    if(isAnswerCorrect) {
      // Play this player's buzz SFX
     
       // Add a point
      playerScore[playerWhoBuzzed]++;    
      // Re-enable all players to buzz for the next question
      Serial.println("CORRECT. Reactivating all players");
      for (int j = 0; j < numPlayers; j++) { activatePlayer(j); }
    }


    // Update the scores
    updateScoreDisplay();


    // Reset the player buzz index
    playerWhoBuzzed = -1;
  }
}


void updateScoreDisplay(){
  Serial.print("Player ");
  char buffer[12];
  for(int i=0; i<numPlayers; i++){
    snprintf(buffer, sizeof(buffer), "%5d", i+1);
    Serial.print(buffer);
  }
  Serial.println("");
  Serial.print("Score  ");
  for(int i=0; i<numPlayers; i++){
    snprintf(buffer, sizeof(buffer), "%5d", playerScore[i]);
    Serial.print(buffer);
  }
  Serial.println("");
}



// Function to deactivate buzzer for a specific player
void deactivatePlayer(int player) {
  playerActive[player] = false;
}


// Function to activate buzzer for a specific player
void activatePlayer(int player) {
  playerActive[player] = true;
}


// Function to pause and wait for the host to input whether the answer is correct or not
bool waitForHostInput() {
  while (true) {
    if (digitalRead(correctButtonPin) == LOW) {
      while(digitalRead(correctButtonPin) == LOW) { delay(100);}
      return true;
    } else if (digitalRead(wrongButtonPin) == LOW) {
      while(digitalRead(wrongButtonPin) == LOW) { delay(100);}
      return false;
    }
  }
}

 

 
The main reason for wanting the switch is that I need to light up LED strips for the player who pressed first. 
 
 
 


   
Quote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2389
 

@the-apprentice

Most strange when I tried to look at your post it was blank. When I tried to reply to the apparently blank post your post was visible in the quote. However when I tried to actually reply my reply was also blank. It appears to be a problem whenever code is inserted.

 

Good day everyone

I'm having problems with the output from my Arduino. I'm using the IRF520 mosfet module board and once I load the program. I only get 3v from the Arduino. There are 6 modules in my project. The 3v will not switch the mosfet. How can I change the voltage? I looked at the video from the workshop (Arduino High-Current Interfacing - Transistors & MOSFETs) using the same module and it works great. Thus I'm thinking it is the code? I'm not a coder, hopping someone will help. 

 

 



   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 2 years ago
Posts: 75
Topic starter  
Here is the code.

// CONSTANTS
const int numPlayers = 6; // Number of players
const int buttonPins[numPlayers] = {A0, A1, A2, A3, A4, A5}; // Pins connected to player buttons
const int ledPins[numPlayers] = {4, 5, 6, 7, 8, 9}; // Pins connected to player LEDs
const int correctButtonPin = 3; // Pin connected to the button for correct answer
const int wrongButtonPin = 12; // Pin connected to the button for wrong answer



// GLOBALS
// If, and which, player has buzzed in
int8_t playerWhoBuzzed = -1;
// Array to track whether each player is active
bool playerActive[numPlayers] = {true, true, true, true, true, true };
int8_t playerScore[numPlayers] = {0, 0, 0, 0, 0, 0 };



void setup() {
  // Initialise a serial connection for debuggin
  Serial.begin(115200);
  Serial.println(__FILE__ __DATE__);


  // Configure pins
  for (int i=0; i<numPlayers; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP);
    pinMode(ledPins[i], OUTPUT);
  }
  pinMode(correctButtonPin, INPUT_PULLUP);
  pinMode(wrongButtonPin, INPUT_PULLUP);


}


void loop() {
  // We check for reset on every loop
  if(digitalRead(correctButtonPin) == LOW) {
    while(digitalRead(correctButtonPin) == LOW) { delay(100);}
    Serial.println("Reactivating all players");
    for (int i=0; i<numPlayers; i++) {
        activatePlayer(i);
      }
  }


  // Check if any player buzzes in
  for (int i = 0; i < numPlayers; i++) {
    // Light up the player's button if they are active
    digitalWrite(ledPins[i], playerActive[i] ? HIGH : LOW);
    // If an active player presses their button
    if (digitalRead(buttonPins[i]) == LOW && playerActive[i]) {
      Serial.print("Player ");
      Serial.print(i+1);
      Serial.println(" buzzed in");
      playerWhoBuzzed = i;
      break;
    }
  }
  // If a player has buzzed in, indicate it and play a sound
  if (playerWhoBuzzed != -1) {


    // Light up only the player who buzzed's LED
    for (int i=0; i<numPlayers; i++) {
      digitalWrite(ledPins[i], (playerWhoBuzzed == i));
    }


    // Wait for the host to confirm whether the answer is correct or not
    bool isAnswerCorrect = waitForHostInput();


    // If the answer is incorrect
    if (!isAnswerCorrect) {
      // Play this player's buzz SFX
     
      // Deduct a point for buzzing in incorrectly
      playerScore[playerWhoBuzzed]--;
      // Lock out this player from answering again
      Serial.print("INCORRECT. Deactivating player ");
      Serial.println(playerWhoBuzzed+1);
      deactivatePlayer(playerWhoBuzzed);


    }
    // If correct
    if(isAnswerCorrect) {
      // Play this player's buzz SFX
     
       // Add a point
      playerScore[playerWhoBuzzed]++;    
      // Re-enable all players to buzz for the next question
      Serial.println("CORRECT. Reactivating all players");
      for (int j = 0; j < numPlayers; j++) { activatePlayer(j); }
    }


    // Update the scores
    updateScoreDisplay();


    // Reset the player buzz index
    playerWhoBuzzed = -1;
  }
}


void updateScoreDisplay(){
  Serial.print("Player ");
  char buffer[12];
  for(int i=0; i<numPlayers; i++){
    snprintf(buffer, sizeof(buffer), "%5d", i+1);
    Serial.print(buffer);
  }
  Serial.println("");
  Serial.print("Score  ");
  for(int i=0; i<numPlayers; i++){
    snprintf(buffer, sizeof(buffer), "%5d", playerScore[i]);
    Serial.print(buffer);
  }
  Serial.println("");
}



// Function to deactivate buzzer for a specific player
void deactivatePlayer(int player) {
  playerActive[player] = false;
}


// Function to activate buzzer for a specific player
void activatePlayer(int player) {
  playerActive[player] = true;
}


// Function to pause and wait for the host to input whether the answer is correct or not
bool waitForHostInput() {
  while (true) {
    if (digitalRead(correctButtonPin) == LOW) {
      while(digitalRead(correctButtonPin) == LOW) { delay(100);}
      return true;
    } else if (digitalRead(wrongButtonPin) == LOW) {
      while(digitalRead(wrongButtonPin) == LOW) { delay(100);}
      return false;
    }
  }
}

 


   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 2 years ago
Posts: 75
Topic starter  

It looks blank again. LOL



   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 2 years ago
Posts: 75
Topic starter  

@robotbuilder 

// CONSTANTS
const int numPlayers = 6; // Number of players
const int buttonPins[numPlayers] = {A0, A1, A2, A3, A4, A5}; // Pins connected to player buttons
const int ledPins[numPlayers] = {4, 5, 6, 7, 8, 9}; // Pins connected to player LEDs
const int correctButtonPin = 3; // Pin connected to the button for correct answer
const int wrongButtonPin = 12; // Pin connected to the button for wrong answer



// GLOBALS
// If, and which, player has buzzed in
int8_t playerWhoBuzzed = -1;
// Array to track whether each player is active
bool playerActive[numPlayers] = {true, true, true, true, true, true };
int8_t playerScore[numPlayers] = {0, 0, 0, 0, 0, 0 };



void setup() {
  // Initialise a serial connection for debuggin
  Serial.begin(115200);
  Serial.println(__FILE__ __DATE__);


  // Configure pins
  for (int i=0; i<numPlayers; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP);
    pinMode(ledPins[i], OUTPUT);
  }
  pinMode(correctButtonPin, INPUT_PULLUP);
  pinMode(wrongButtonPin, INPUT_PULLUP);


}


void loop() {
  // We check for reset on every loop
  if(digitalRead(correctButtonPin) == LOW) {
    while(digitalRead(correctButtonPin) == LOW) { delay(100);}
    Serial.println("Reactivating all players");
    for (int i=0; i<numPlayers; i++) {
        activatePlayer(i);
      }
  }


  // Check if any player buzzes in
  for (int i = 0; i < numPlayers; i++) {
    // Light up the player's button if they are active
    digitalWrite(ledPins[i], playerActive[i] ? HIGH : LOW);
    // If an active player presses their button
    if (digitalRead(buttonPins[i]) == LOW && playerActive[i]) {
      Serial.print("Player ");
      Serial.print(i+1);
      Serial.println(" buzzed in");
      playerWhoBuzzed = i;
      break;
    }
  }
  // If a player has buzzed in, indicate it and play a sound
  if (playerWhoBuzzed != -1) {


    // Light up only the player who buzzed's LED
    for (int i=0; i<numPlayers; i++) {
      digitalWrite(ledPins[i], (playerWhoBuzzed == i));
    }


    // Wait for the host to confirm whether the answer is correct or not
    bool isAnswerCorrect = waitForHostInput();


    // If the answer is incorrect
    if (!isAnswerCorrect) {
      // Play this player's buzz SFX
     
      // Deduct a point for buzzing in incorrectly
      playerScore[playerWhoBuzzed]--;
      // Lock out this player from answering again
      Serial.print("INCORRECT. Deactivating player ");
      Serial.println(playerWhoBuzzed+1);
      deactivatePlayer(playerWhoBuzzed);


    }
    // If correct
    if(isAnswerCorrect) {
      // Play this player's buzz SFX
     
       // Add a point
      playerScore[playerWhoBuzzed]++;    
      // Re-enable all players to buzz for the next question
      Serial.println("CORRECT. Reactivating all players");
      for (int j = 0; j < numPlayers; j++) { activatePlayer(j); }
    }


    // Update the scores
    updateScoreDisplay();


    // Reset the player buzz index
    playerWhoBuzzed = -1;
  }
}


void updateScoreDisplay(){
  Serial.print("Player ");
  char buffer[12];
  for(int i=0; i<numPlayers; i++){
    snprintf(buffer, sizeof(buffer), "%5d", i+1);
    Serial.print(buffer);
  }
  Serial.println("");
  Serial.print("Score  ");
  for(int i=0; i<numPlayers; i++){
    snprintf(buffer, sizeof(buffer), "%5d", playerScore[i]);
    Serial.print(buffer);
  }
  Serial.println("");
}



// Function to deactivate buzzer for a specific player
void deactivatePlayer(int player) {
  playerActive[player] = false;
}


// Function to activate buzzer for a specific player
void activatePlayer(int player) {
  playerActive[player] = true;
}


// Function to pause and wait for the host to input whether the answer is correct or not
bool waitForHostInput() {
  while (true) {
    if (digitalRead(correctButtonPin) == LOW) {
      while(digitalRead(correctButtonPin) == LOW) { delay(100);}
      return true;
    } else if (digitalRead(wrongButtonPin) == LOW) {
      while(digitalRead(wrongButtonPin) == LOW) { delay(100);}
      return false;
    }
  }
}
 
 
 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2389
 

@the-apprentice 

Attach the file rather than trying to copy it into the post.

 



   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2389
 

@the-apprentice 

I have attached the .ino file for you.

Good day everyone

I'm having problems with the output from my Arduino. I'm using the IRF520 mosfet module board and once I load the program. I only get 3v from the Arduino. There are 6 modules in my project. The 3v will not switch the mosfet. How can I change the voltage? I looked at the video from the workshop (Arduino High-Current Interfacing - Transistors & MOSFETs) using the same module and it works great. Thus I'm thinking it is the code? I'm not a coder, hopping someone will help. 

This is a simple quiz game controller I'm trying to built. Took the code from alastaira
 
The main reason for wanting the switch is that I need to light up LED strips for the player who pressed first.

 



   
ReplyQuote
(@davee)
Member
Joined: 5 years ago
Posts: 2006
 

Hi @the-apprentice,

  You mention "I only get 3v from the Arduino.", which, as you say, will not be sufficient for an IRF520.

   I assume you are using a 5V Arduino, like the 'original' UNO, and not one of the more recent models with 3.3V processors. If that is not the problem, then, in the absence of a full hardware description, we can only guess what your system looks like, which makes diagnosis difficult.

-----------------------

   May I suggest you start with a much simpler programme, but using the same hardware. Namely, use the ubiquitous Blink programme, as described at https://docs.arduino.cc/built-in-examples/basics/Blink/

And conveniently found in the Examples part of the Arduino IDE,

with "LED_BUILTIN" replaced (in three different lines) by the appropriate GPIO pin number to drive the MOSFET,

and the delay times set to a longer convenient value of say 5000 (5 seconds), so that your voltmeter can show the 'ON' and 'OFF' voltages at the GPIO pin.

Then report back with your findings.

Best wishes and good luck, Dave



   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 5 years ago
Posts: 8047
 

@the-apprentice What are you using the IRF520 for? Looking at your code, there are numplayers of LED pins. If that is all you are controlling, you don't need the MOSFET, you can drive a LED directly from the pins.


First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 2 years ago
Posts: 75
Topic starter  

I'm driving 20 leds per channel/player. The UNO wont light them. If I use the simple program the mosfet switches. I'm using the UNO and have it pluged in to the USB and have a 9 volt supply pluged in to the power socket of the UNO. The LEDs are driven from an external 12v supply.



   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 2 years ago
Posts: 75
Topic starter  

@robotbuilder  Thank you



   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2389
 

@the-apprentice 

What I don't understand is why you would only have 3v from a UNO.

Seems like a clone or a faulty UNO?

This is a simple quiz game controller I'm trying to built. Took the code from alastaira

An actual link address may help. If alastaira was a link it didn't work in the quote where I obtained your actual post text. 



   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 5 years ago
Posts: 8047
 

@the-apprentice Why do you have a 9V and the USB? One of those will power the UNO.


First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 5 years ago
Posts: 2006
 

Hi @the-apprentice,

RE:

I'm driving 20 leds per channel/player. The UNO wont light them. If I use the simple program the mosfet switches. I'm using the UNO and have it pluged in to the USB and have a 9 volt supply pluged in to the power socket of the UNO. The LEDs are driven from an external 12v supply.

I agree 20 LEDs would be much more than a UNO could drive directly.

You then add "If I use the simple program the mosfet switches. ", which suggests the UNO is achieving the required task.

If a development card/Arduino/etc., such as a UNO, is connected by USB to a development host computer, then that will usually supply enough power to supply the processor. Similarly, a suitable 9V supply to a UNO would also be sufficient for the processor.

In general, it is not good practice to supply power by both routes at the same time, albeit, that is unlikely to be a problem in this case.

Driving the LEDs from an external supply seems sensible, although you do not explain how the 12V supply is related to current control supply required by individual LED diodes.

----------------

So I am completely in the dark as to what your circuit looks like, and the relationship between the "simple program" case, which you say "works", and your project circuit.

Sorry, you are not providing enough information to even begin to understand your situation, so diagnosis is impossible. You need to provide sketches of your wiring, as well as explaining which the software situation more clearly.

Best wishes, Dave



   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 2 years ago
Posts: 75
Topic starter  

The USB is used just for the serial monitor. The UNO is the Rev3 variant( https://www.communica.co.za/products/ard-uno-rev3?variant=17184558284873) I have tried with the leonardo and the minima Rev4 ( https://www.communica.co.za/products/arduino-uno-rev-4-minima?variant=49797996544300). All with the same result. I will make a drawing soon.



   
ReplyQuote
Page 1 / 2